package com.panshi.controller.user;
import com.panshi.api.UserApi;
import com.panshi.bean.PageBean;
import com.panshi.po.SystemUserPo;
import com.panshi.po.UserPO;
import com.panshi.vo.PageModel;
import com.panshi.vo.UserFindByVagueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户管理
 */
@Controller
@Slf4j
public class UserController {

    @Autowired
    private UserApi userApi;

    @GetMapping("query")
    public  String query(){

        return "user/user-query";
    }


    /**
     * 查询全部
     * @param pm
     * @return
     */
    @PostMapping("user-queryall")
    @ResponseBody
    public PageModel<UserPO> queryall(PageModel<UserPO> pm){
        pm.init();
        PageBean pageBean=new PageBean();
        log.info("pageBean=========={}",pageBean);
        pageBean.setCurrentPage(pm.getCurrentPage());
        pageBean.setCurrentPageSize(pm.getPageSize());
        List<UserPO> list=userApi.findUserByAll(pageBean).getData();
        log.info("list============{}",list);

      Integer  count= userApi.findAllCount();
        log.info("count============{}",count);
        pm.setCount(count);
        pm.setList(list);

        return pm;
    }


    /**
     * 模糊查询
     * @param pa
     * @param vague
     * @return
     */
    @PostMapping("user-queryDim/{vague}")
    @ResponseBody
    public  PageModel<UserPO>  queryDim(PageModel<UserPO> pa,@PathVariable String vague){
        pa.init();
        log.info("vague============={}",vague);
        UserFindByVagueVO findByVagueVO=new UserFindByVagueVO();
        findByVagueVO.setVague(vague);
        findByVagueVO.setCurrentPage(pa.getCurrentPage());
        findByVagueVO.setCurrentPageSize(pa.getPageSize());

        log.info("findByVagueVO======={}",findByVagueVO);
        List<UserPO>  list=userApi.findUserByVague(findByVagueVO).getData();
        log.info("list========={}",list);

       Integer integer= userApi.findVagueCount(vague);
        pa.setCount(integer);
        pa.setList(list);

        return pa;
    }


}
